package com.qianda.qdminiapp.controller.device;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianda.qdminiapp.common.exception.ExceptionCode;
import com.qianda.qdminiapp.common.exception.SimpleException;
import com.qianda.qdminiapp.config.CompanyProperties;
import com.qianda.qdminiapp.controller.Result;
import com.qianda.qdminiapp.dao.device.QqdDeviceDao;
import com.qianda.qdminiapp.domain.model.device.QqdDevice;
import com.qianda.qdminiapp.security.SecurityUser;
import com.qianda.qdminiapp.service.QqdDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author cw
 * @since 2019-08-14
 */
@RestController
@RequestMapping("/qqd-device")
@EnableConfigurationProperties({ CompanyProperties.class })
public class QqdDeviceController {

    @Autowired
    private QqdDeviceService qqdDeviceService;

    @Autowired
    private QqdDeviceDao qqdDeviceDao;

    @Autowired
    private CompanyProperties companyProperties;

    @GetMapping("/findByImei")
    private Result findDevice(String imei){
        return Result.success(qqdDeviceService.findByImei(imei));
    }

    @GetMapping("/findById")
    private Result findById(Long id,@AuthenticationPrincipal SecurityUser user){

        QqdDevice device =qqdDeviceService.findById(id,user.getId());

        if(device == null){
            throw new SimpleException(ExceptionCode.EX_DEVICE_ERROR);
        }
        return Result.success(device);
    }

    @GetMapping("/findSign")
    private Result findDeviceSign(String imei){
        return Result.success(qqdDeviceService.findSign(imei));
    }

}

